home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl1 / labs / stars.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  1.9 KB  |  83 lines

  1. /*
  2.  * Copyright 1993, 1995, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /*
  19.  * stars.c
  20.  *
  21.  * functions to initialize and draw a bunch of stars
  22.  *
  23.  * init_stars() code courtesy of David Marsland.
  24.  *
  25.  * Copyright 1993, Silicon Graphics, Inc.
  26.  * All Rights Reserved.
  27.  */
  28. #include <stdlib.h>
  29. #include <GL/gl.h>
  30. #include "stars.h"
  31.  
  32. /*            init_stars()
  33.  *    init_stars() initializes array of MAXSTARS stars in 3-D  
  34.  */
  35.  
  36. #define MAXSTARS 1000   /* number of stars */
  37.  
  38. static  float starcol[MAXSTARS][4];
  39. static     float star[MAXSTARS][3];
  40.  
  41. void init_stars(void)
  42. {
  43.     int j, k;
  44.  
  45.     for (j = 0; j < MAXSTARS ; j++)
  46.     {
  47.         for (k = 0; k < 3; k++)
  48.         {
  49.             /* x,y,z */
  50.             star[j][k] = (GLfloat) rand()/(GLfloat) RAND_MAX - 0.5;
  51.  
  52.         }
  53.         starcol[j][0] = starcol[j][1] = starcol[j][2] = starcol[j][3] =
  54.                     0.3 + 0.7 * rand()/(GLfloat)RAND_MAX;
  55.         starcol[j][3] = 1.0;
  56.     }
  57. }
  58.  
  59. /*            draw_stars()
  60.  *    draw_stars() draws MAXSTARS stars in 3-D  
  61.  */
  62. void draw_stars( GLfloat distance )
  63. {
  64.     int i;
  65.  
  66.     glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_POINT_BIT );
  67.     glDisable( GL_DEPTH_TEST );
  68.     glPointSize( 2.5 );
  69.  
  70.     glPushMatrix();
  71.         glScalef( distance, distance, distance );
  72.         glBegin(GL_POINTS);
  73.             for(i = 0; i < MAXSTARS; i++)
  74.             {
  75.                 glColor4fv(&starcol[i][0]);
  76.                 glVertex3fv(&star[i][0]);   /*  x,y,z  */
  77.             }
  78.         glEnd();
  79.     glPopMatrix();
  80.     
  81.     glPopAttrib();
  82. }
  83.